package test3.demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dell
 * Date: 2023-11-27
 * Time: 22:18
 */
public class Computer {
    public void open(){
        System.out.println("启动");
    }
    public void close(){
        System.out.println("结束");
    }
    public void start(USB usb){
        usb.openDevice();//重写
        if(usb instanceof Mouse){
            //((Mouse) usb).click();
            Mouse mouse=(Mouse) usb;
            mouse.click();
        }
        else if(usb instanceof KeyBoard){
            KeyBoard keyBoard=(KeyBoard) usb;
            keyBoard.input();
        }
        usb.closeDevice();//重写
    }
    public static void main(String[] args) {
        Computer computer=new Computer();
        computer.open();
        computer.start(new KeyBoard());
        System.out.println("===================");
        computer.start(new Mouse());
        computer.close();
    }
}